n = int(input())
N = 200 + 5
M = 10000 + 5
v = [0 for i in range(0, N)]
c = [0 for i in range(0, N)]
f = [0 for i in range(0, M)] 
for i in range(1, n + 1):   
    s = input().split()
    v[i] = int(s[0])
    c[i] = int(s[1])
m = int(input())

for i in range(1, n + 1):
    for j in range(m, -1, -1):
        if j - v[i] >= 0:
            f[j] = max(f[j], f[j - v[i]] + c[i])
print(f[m])